/**
 * Created by mooshroom on 2015/3/10.
 */
module.exports = function (grunt) {

    // 项目配置
    grunt.initConfig({



        pkg: grunt.file.readJSON('package.json'),

        clean: {
            build: {
                src: ['build']
            }
        },

        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
                mangle: true
            }

            //压缩JS文件
            , build: {
                files: [
                    {
                        expand: true,
                        cwd: 'plugins',
                        src: '**/*.js',
                        dest: 'build/plugins'
                    },
                    {
                        expand: true,
                        cwd: 'soul',
                        src: '**/*.js',
                        dest: 'build/soul'
                    },
                    {
                        expand: true,
                        cwd: 'src',
                        src: '**/*.js',
                        dest: 'build/src'
                    }
                ]
            }

            //压缩合并路由，配置，引入
            , release: {
                files: {
                    'build/all.js': ['config.js', 'router.js', 'include.js']
                }
            }

        }
        //合并CSS文件
        , concat: {
            options: {

            },
            dist: {
                src: ['src/css/bootstrap.css', 'src/css/mooshroom.css', 'src/css/local.css'],
                dest: 'build/src/css/all.css'
            }

        }
        //压缩CSS文件
        ,
        cssmin: {
            cssRelease: {
                src: 'build/src/css/all.css',
                dest: 'build/src/css/all.min.css'
            }
        },

        //复制文件
        copy: {
            body: {
                files: [
                    {
                        //TODO 文件复制路径不对头的问题有待解决
                        expand: true,
                        cwd: 'body',
                        src: ['**/*.html'],
                        dest: 'build/body'

                    }
                ]
            },
            src: {
                files: [
                    {
                        expand: true,
                        cwd: 'src',
                        src: '**/*.*',
                        dest: 'build/src'

                    }
                ]
            }


        },

        //打包
        compress: {
            main: {
                options:{
                    archive:'build.zip'
                },
                files:[{
                    expand: true,
                    cwd: 'build',
                    src: '**/*.*',
                    dest: './'
                }]
            }
        }



    });
    // 加载任务的插件
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-css');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks("grunt-contrib-clean");
    grunt.loadNpmTasks("grunt-contrib-compress");
    // 默认任务
    grunt.registerTask('default', ['copy', 'uglify', 'concat', 'cssmin', 'compress']);
    grunt.registerTask('css', [ 'cssmin']);
    grunt.registerTask('copyTo', [ 'copy']);
    grunt.registerTask('cleanUp', [ 'clean']);
    grunt.registerTask('zip', [ 'compress']);
}